﻿namespace Example.Controllers
{
    using System.Web.Mvc;

    using Example.Models;

    using Microsoft.Practices.ServiceLocation;

    using Moq;

    using Xunit;

    public sealed class InfoControllerFacts
    {
        [Fact]
        public void ctor()
        {
            Assert.NotNull(new InfoController());
        }

        [Fact]
        public void op_HtmlRepresentation_string()
        {
            try
            {
                const string id = "example";
                var info = new InfoViewModel
                               {
                                   Id = id,
                                   Title = "Example"
                               };
                var provider = new Mock<IProvideViewModels>();
                provider
                    .Setup(x => x.Info(id))
                    .Returns(info)
                    .Verifiable();

                var locator = new Mock<IServiceLocator>();
                locator
                    .Setup(x => x.GetInstance<IProvideViewModels>())
                    .Returns(provider.Object)
                    .Verifiable();
                ServiceLocator.SetLocatorProvider(() => locator.Object);

                var controller = new InfoController();

                Assert.IsType<ViewResult>(controller.HtmlRepresentation(id));

                provider.VerifyAll();
                locator.VerifyAll();
            }
            finally
            {
                ServiceLocator.SetLocatorProvider(null);
            }
        }
    }
}